﻿using System;
using System.Text;

namespace AnyBaseToAnyBase
{
    class AnyBaseToAnyBase
    {
        static char GetSymbol(int number)
        {
            if (number > 9)
            {
                return (char)(55 + number); // 55 + 10 = 65 in ASCII = 'A'
            }
            return (char)(number + '0');
        }
        static string ConvertDecimalToAnymal(int number, int any)
        {
            StringBuilder result = new StringBuilder();
            while (number > 0)
            {
                result.Insert(0, GetSymbol(number % any));
                number /= any;
            }
            return result.ToString();
        }
        static int GetNumber(char symbol)
        {
            if (char.IsLetter(symbol))
            {
                return (symbol + 10) - 'A';
            }
            return symbol - '0';
        }
        static int ConvertAnymalToDecimal(string number, int any)
        {
            number = number.ToUpper();
            int result = 0;
            for (int index = number.Length - 1, times = 1; index >= 0; index--, times *= any)
            {
                result += GetNumber(number[index]) * times;
            }
            return result;
        }
        static void Main()
        {
            int baseOne = 36;
            int baseTwo = 2;
            string userInput = "ZZ";
            int decimalResult = ConvertAnymalToDecimal(userInput, baseOne);
            Console.WriteLine(ConvertDecimalToAnymal(decimalResult, baseTwo));
        }
    }
}
